<div class="row">
	<div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
		<h4 class="page-title txt-color-blueDark">
			<i class="fa fa-fw fa-user"></i> 用户管理
		</h4>
	</div>
</div>

<!-- widget grid -->
<section id="widget-grid" class="">
	<div class="row">
		<article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
			<div class="jarviswidget" id="wid-id-0"
				data-widget-editbutton="false" data-widget-togglebutton="false"
				data-widget-fullscreenbutton="false"
				data-widget-deletebutton="false">
				<header>
					<h2>用户信息表</h2>
				</header>
				<div>
					<div class="jarviswidget-editbox"></div>
					<div class="widget-body no-padding">
						<table id="dt_basic"
							class="table table-striped table-bordered table-hover"
							style="width: 100%;">
							<thead>
								<tr>
									<th data-hide="phone">序号</th>
									<th data-class="expand">用户</th>
									<th data-hide="phone">邮箱</th>
									<th data-hide="phone">姓名</th>
									<th data-hide="phone">性别</th>
									<th data-hide="phone">角色</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								#for(user:userlist)
								<tr>
									<td>#(for.count)</td>
									<td>#(user.user)</td>
									<td>#(user.email)</td>
									<td>#(user.name)</td>
									<td>#if(user.sex == 1) #("男") #else #("女") #end</td>
									<td>#(user.role)</td>
									<td><a href="user/edit/#(user.id)" data-toggle="modal"
										data-target="#UserModal" class="btn btn-xs btn-default"
										rel="tooltip" data-placement="bottom" title="编辑"><i
											class="fa fa-pencil"></i></a><a
										href="user/editpassword/#(user.id)" data-toggle="modal"
										data-target="#UserModal" class="btn btn-xs btn-default"
										rel="tooltip" data-placement="bottom" title="修改密码"><i
											class="fa fa-lock"></i></a><a href="user/initpassword/#(user.id)"
										data-action="initPassword"
										class="btn btn-xs btn-default #if(userrole != 0) disabled #end"
										rel="tooltip" data-placement="bottom" title="重置密码"><i
											class="fa fa-undo"></i></a><a
										href="javascript:userdelete(#(user.id));"
										data-action="dataDelete"
										class="btn btn-xs btn-default #if(userrole != 0) disabled #end"
										rel="tooltip" data-placement="bottom" title="删除"><i
											class="fa fa-trash-o"></i></a></td>
								</tr>
								#end
							</tbody>
						</table>

					</div>
				</div>
			</div>
		</article>
	</div>
</section>
<!-- end widget grid -->
<!-- Modal -->
<div class="modal fade" id="UserModal" tabindex="-1" role="dialog"
	aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog">
		<div class="modal-content"></div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal-dialog -->
</div>
<!-- /.modal -->

<script type="text/javascript">
	pageSetUp();

	// pagefunction	
	var pagefunction = function() {

		/* BASIC */
		var responsiveHelper_dt_basic = undefined;
		var breakpointDefinition = {
			tablet : 1024,
			phone : 480
		};

		$('#dt_basic')
				.dataTable(
						{
							"columnDefs": [{ "orderable": false, "targets": 6 }],
							"sDom" : "<'dt-toolbar'<'col-xs-6 col-sm-6'<'adduser'>><'col-xs-6 col-sm-5 hidden-xs'f><'col-xs-6 col-sm-1'l>r>"
									+ "t"
									+ "<'dt-toolbar-footer'<'col-xs-12 col-sm-6 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
							"oLanguage" : {
								"sProcessing" : "处理中...",
								"sLengthMenu" : "_MENU_",
								"sZeroRecords" : "没有匹配记录",
								"sInfo" : "显示第 _START_ 条至 _END_ 条记录，共 _TOTAL_ 条",
								"sInfoEmpty" : "显示第 0 条至 0 条记录，共 0 条",
								"sInfoFiltered" : "(由 _MAX_ 条记录过滤)",
								"sInfoPostFix" : "",
								"sSearch" : '<span class="input-group-addon"><i class="fa fa-search"></i></span>',
								"sSearchPlaceholder" : "筛选",
								"sEmptyTable" : "表中数据为空",
								"sLoadingRecords" : "载入中...",
								"sInfoThousands" : ",",
								"oPaginate" : {
									"sFirst" : "首页",
									"sPrevious" : "上页",
									"sNext" : "下页",
									"sLast" : "末页"
								},
								"oAria" : {
									"sSortAscending" : ": 以升序排列此列",
									"sSortDescending" : ": 以降序排列此列"
								}

							},
							"autoWidth" : true,
							"preDrawCallback" : function() {
								// Initialize the responsive datatables helper once.
								if (!responsiveHelper_dt_basic) {
									responsiveHelper_dt_basic = new ResponsiveDatatablesHelper(
											$('#dt_basic'),
											breakpointDefinition);
								}
							},
							"rowCallback" : function(nRow) {
								responsiveHelper_dt_basic
										.createExpandIcon(nRow);
							},
							"drawCallback" : function(oSettings) {
								responsiveHelper_dt_basic.respond();
							}
						});
		// custom toolbar
		$("div.adduser")
				.html(
						'<div class="btn-group"><a href="user/add" data-toggle="modal" data-target="#UserModal" class="btn btn-default #if(userrole != 0) disabled #end"><i class="fa fa-plus"></i> 新建用户信息</a></div>');
		/* END BASIC */

	};

	// load related plugins

	loadScript(
			"#(ContextPath)/static/js/plugin/datatables/jquery.dataTables.min.js",
			function() {
				loadScript(
						"#(ContextPath)/static/js/plugin/datatables/dataTables.colVis.min.js",
						function() {
							loadScript(
									"#(ContextPath)/static/js/plugin/datatables/dataTables.tableTools.min.js",
									function() {
										loadScript(
												"#(ContextPath)/static/js/plugin/datatables/dataTables.bootstrap.min.js",
												function() {
													loadScript(
															"#(ContextPath)/static/js/plugin/datatable-responsive/datatables.responsive.min.js",
															pagefunction)
												});
									});
						});
			});

	function userdelete(userid) {
		var ajaxobj = $.ajax({
			url : "user/delete/" + userid,
			dataType : "text",
			async : false
		});
		if(ajaxobj.responseText != '1'){
			alert(ajaxobj.responseText);
		}
		window.location.reload();
	}
</script>